<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="layout">
	<tiles:putAttribute name="head">
		<script type="text/javascript">
	    $(function() {
		$(".date").datepicker({
		    showWeek : true,
		    firstDay : 1,
		    dateFormat : 'yy-mm-dd',
		    showOtherMonths : true,
		    selectOtherMonths : true,
		});

		$("form").Validform({
		    ajaxPost : true,
		    tiptype : ValidUtils.siblingTip,
		    callback : function(data) {
			helper.showMsg(data, {
			    okHandler : function() {
				location = "../log/viewLogByTime?id=" + data.id;
			    }
			});
		    }
		});

		$('#term_select_menu li a').click(function(e) {
		    var v = $(this).text();
		    changeTermVal(v);
		});

		$('#times_select_menu li a').click(function(e) {
		    var v = $(this).text();
		    $(':input[name=times]').val(v);
		});

		$(':input[name=beginTime]').change(changeEndTime);

		var oldvalue = $(':input[name=term]').val();
		$(':input[name=term]').keyup(function() {
		    var v = $(':input[name=term]').val();
		    if (v && v != oldvalue) {
			oldvalue = v;
			changeEndTime();
		    }
		});

		$(':input[name=term],:input[name=times]').keydown(function(e) {
		    var code = e.which;
		    if (!e.shiftKey && (code == 8 || (code > 47 && code < 58))) {
			return true;
		    } else {
			return false;
		    }
		});

		function changeTermVal(val) {
		    $(':input[name=term]').val(val);
		    changeEndTime();
		}

		function changeEndTime() {
		    var btime = $(':input[name=beginTime]').val();
		    if (btime) {
			var timepart = btime.split('-');

			var mt = $(':input[name=term]').val();

			var flag = 0;

			var month = parseInt(timepart[1]) + parseInt(mt);
			if (month > 12) {
			    flag = parseInt(month / 12);
			    month = month % 12;
			}
			var year = parseInt(timepart[0]) + flag;

			$(':input[name=endTime]').val(year + '-' + month + '-' + timepart[2]);
		    }
		}
	    });
	</script>
	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<ul class="breadcrumb">
			<li><s:url action="listStudent" namespace="/student" id="listStudent">
				</s:url> <a href="${listStudent}">学员管理</a> <span class="divider">/</span></li>
			<li><s:url action="viewLogByTime" namespace="/log" id="viewLogByTime">
					<s:param name="id" value="#signCourse.student.id"></s:param>
				</s:url> <a href="${viewLogByTime}">学员日志</a> <span class="divider">/</span></li>
			<li class="active">注册课程修改</li>
		</ul>
		<form class="form-horizontal" action="doModifySignCourse">
			<input name="id" value="${signCourse.id}" type="hidden" />
			<fieldset>
				<legend>注册课程修改</legend>
				<div class="control-group">
					<div class="control-label">选择课程</div>
					<div class="controls">
						<s:select list="courses" listKey="id" listValue="name" name="courseId" size="courses.size">
						</s:select>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">合同号</div>
					<div class="controls">
						<input type="text" value="${signCourse.contractId}" name="contractId" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">听课证号</div>
					<div class="controls">
						<input type="text" name="lessonCard" value="${signCourse.lessonCard}" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">卡号</div>
					<div class="controls">
						<input type="text" name="cardId" value="${signCourse.cardId}" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">期限</div>
					<div class="controls">
						<div class="input-prepend input-append">
							<div class="btn-group">
								<button class="btn dropdown-toggle" data-toggle="dropdown">
									<span class="caret"></span>
								</button>
								<ul class="dropdown-menu" id="term_select_menu">
									<li><a href="javascript:void(0)">12</a></li>
									<li><a href="javascript:void(0)">11</a></li>
									<li><a href="javascript:void(0)">10</a></li>
									<li><a href="javascript:void(0)">9</a></li>
									<li><a href="javascript:void(0)">8</a></li>
									<li><a href="javascript:void(0)">7</a></li>
									<li><a href="javascript:void(0)">6</a></li>
									<li><a href="javascript:void(0)">5</a></li>
									<li><a href="javascript:void(0)">4</a></li>
									<li><a href="javascript:void(0)#">3</a></li>
								</ul>
							</div>
							<input name="term" class="span9" type="text" value="12"> <span class="add-on">个月</span>
						</div>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">开课日期</div>
					<div class="controls">
						<input class="date" type="text" name="beginTime" value="${begin}" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">结课日期</div>
					<div class="controls">
						<input type="text" name="endTime" value="${end}" readonly="readonly" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">课次</div>
					<div class="controls">
						<div class="input-prepend input-append">
							<div class="btn-group">
								<button class="btn dropdown-toggle" data-toggle="dropdown">
									<span class="caret"></span>
								</button>
								<ul class="dropdown-menu" id="times_select_menu">
									<li><a href="javascript:void(0)">无限次</a></li>
									<li><a href="javascript:void(0)">50</a></li>
									<li><a href="javascript:void(0)">100</a></li>
									<li><a href="javascript:void(0)">150</a></li>
									<li><a href="javascript:void(0)">200</a></li>
								</ul>
							</div>
							<input name="times" class="span9" type="text" value="${signCourse.times}"> <span class="add-on">&nbsp;&nbsp;次&nbsp;&nbsp;</span>
						</div>
						<span class="help-block">0次表示无限制</span>
					</div>
				</div>
			</fieldset>
			<div class="control-group">
				<div class="controls">
					<button type="submit" class="btn btn-primary">
						<i class="icon-ok icon-white"></i>提交
					</button>
				</div>
			</div>
		</form>
	</tiles:putAttribute>
</tiles:insertDefinition>